<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script src="${pageContext.request.contextPath}/bootstrap3/js/jquery-1.11.2.min.js"></script>

<script type="text/javascript">

$(document).ready(function(){
	//IE 判定
	if ((navigator.userAgent.indexOf('MSIE') < 0) ){
		$("#tips").html('请使用IE浏览器自动获取电脑信息！');
		return;
	}
	//生成ActiveX对象
	var locator = new ActiveXObject ("WbemScripting.SWbemLocator"); 
	var service = locator.ConnectServer(".");
	//CPU
	var properties = service.ExecQuery("SELECT * FROM Win32_Processor"); 
	var e = new Enumerator (properties); 
	var infoCPU="";
	for (;!e.atEnd();e.moveNext ()) { 
		var i = e.item ();
		infoCPU+=i.Name+'('+i.MaxClockSpeed+'MHz)';
	}
	//内存
    var memory = new Enumerator (service.ExecQuery("SELECT * FROM Win32_PhysicalMemory")); 
    for (var mem=[],i=0;!memory.atEnd();memory.moveNext()){ 
		mem[i++]={cap:memory.item().Capacity/1024/1024,speed:memory.item().Speed};
    }
    var infoDDR = 0;
    for(var mi=0;mi<mem.length;mi++){
    	infoDDR += mem[mi].cap;
	}
    infoDDR += 'MB';
    //MAC IP
    properties = service.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration Where IPEnabled=TRUE");
 	e = new Enumerator (properties);
 	var infoIP='';
 	var infoMAC='';
	for (;!e.atEnd();e.moveNext ()){
	 var p = e.item ();
	 infoMAC+=p.MACAddress;
	 infoIP+=p.IPAddress(0);
	 i++;
	}
	
	//主板
	properties = service.ExecQuery("SELECT * FROM Win32_BaseBoard"); 
	e = new Enumerator (properties); 
	var infoBB="";
	for (;!e.atEnd();e.moveNext ()){
		 var p = e.item ();
		 infoBB=p.Product+'('+p.Manufacturer+')';
		 i++;
		}
	
	//硬盘
	properties = service.ExecQuery("SELECT * FROM Win32_DiskDrive"); 
	e = new Enumerator (properties); 
	var infoDD="";
	for (;!e.atEnd();e.moveNext ()){
		 var p = e.item ();
		 infoDD=parseInt(p.Size/1024/1024/1024)+'G';
		 i++;
		}
	
	//操作系统
	properties = service.ExecQuery("SELECT * FROM Win32_OperatingSystem"); 
	e = new Enumerator (properties); 
	var infoOS="";
	var infoCSN="";
	for (;!e.atEnd();e.moveNext ()){
		 var p = e.item ();
		 infoOS=p.Caption+" "+p.CSDVersion;
		 infoCSN=p.CSName;
		 i++;
		}
	
	$("#baseB").html(infoBB);
	$("#cpu").html(infoCPU);
	$("#memory").html(infoDDR);
	$("#DiskDrive").html(infoDD);
	$("#OperatingSystem").html(infoOS);
	$("#CSName").html(infoCSN);
	
	$("#MAC").html(infoMAC);
	$("#IP").html(infoIP);
});
</script>
</head>
<body>
<span style="color: red" id="tips"></span><br/>
MAC：<span id="MAC"></span><br/>
IP：<span id="IP"></span><hr/>

主板：<span id="baseB"></span><br/>
CPU：<span id="cpu"></span><br/>
内存：<span id="memory"></span><br/>
硬盘：<span id="DiskDrive"></span><br/>
操作系统：<span id="OperatingSystem"></span><br/>
计算机名：<span id="CSName"></span><br/>

</body>
</html>